<?php


use App\Spider\HttpClientLogic;
use EasySwoole\HttpClient\HttpClient;
use EasySwoole\Utility\File;
use QL\QueryList;

include "./vendor/autoload.php";


go(function () {
    $url = "https://www.doutula.com/article/detail/2844806";

    $response = HttpClientLogic::getHtmlContent($url);
    $html = $response->getBody();

    var_dump($html);

    $ql = QueryList::html($html);
    $rules = [
        'src' => ['img', 'src'],
        'alt' => ['img', 'alt'],
    ];
    //获取当前图片详情的标题
    $title   = trim($ql->find('.pic-title a')->html());
    var_dump($title);

    $rt = $ql->rules($rules)->range('.artile_des')->queryData();
    var_dump($rt);

    //获取url最后的后缀
    $data = $rt[0];
    $pathInfo   = pathinfo($data['src']);
    var_dump($pathInfo);
    $file       = "./Down/{$title}/" . "{$pathInfo['basename']}";
    echo $file;
    $httpClient = new HttpClient($data['src']);
    File::createFile($file, '');
    $result = $httpClient->download($file);

    var_dump($result);
});


